package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.IndustryCache;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserInfoHelper;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 11 细分重点产品 USER_ITEM_INFOS.ORD10052 110WLW10109974有数据
 */
@Service
@UserAttrSupplier(attrField = LocalKeyConsts.SEGMENT_KEY_PRODUCT_NEW)
public class SegmentKeyProductAnotherSupplier extends AbstractUserAttrSupplier {

    @Override
    public String getValue() {
        String detailProdVal = UserInfoHelper.getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(),
            LocalKeyConsts.SEGMENT_KEY_PRODUCT);
        if (KiteStringUtils.isEmpty(detailProdVal)) {
            detailProdVal = UserInfoHelper.getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(),
                LocalKeyConsts.SEGMENT_KEY_PRODUCT_NEW);
        }
        return detailProdVal;
    }

    @Override
    public String getValueDesc() {
        String detailProdVal = getValue();
        return Optional.ofNullable(IndustryCache.getIndustryName(detailProdVal)).orElse(detailProdVal);
    }
}
